package prototyping.client.student.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.UnknownHostException;

import javax.swing.JLabel;
import javax.swing.JTextArea;

import dao.server.DataLoadIP;
import account.student.view.StudentViewSmall;

import java.util.Timer;
import java.util.TimerTask;

import prototyping.client.HelpMessage;
import prototyping.client.student.model.StudentClient;
import prototyping.client.teacher.model.TeacherClient;
import tools.language.MentionChat;

public class HelpButtonController implements ActionListener {
	private Timer timer;
	private StudentClient studentClient;
	
	public HelpButtonController(String userName, String server) {
		studentClient = new StudentClient(server, userName);
		studentClient.start();
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0 ) {
		String action = arg0.getActionCommand();
		
		try {
			HelpMessage hmsg;
		hmsg = new HelpMessage(studentClient.getUsername() + ": " + action);
		studentClient.sendMessage(hmsg);
			HelpMessage t= new HelpMessage("De volgende vraag is gesteld: " + action);
			if(studentClient.sendMessage(hmsg))
			{
				//schakel tijdelijk de hulpvraagknoppen uit
				StudentViewSmall.getInstance().getBtnDAB().setEnabled(false);
				StudentViewSmall.getInstance().getBtnPRG().setEnabled(false);
				StudentViewSmall.getInstance().getBtnPRJ().setEnabled(false);
				StudentViewSmall.getInstance().getBtnBPV().setEnabled(false);
				StudentViewSmall.getInstance().getConfirmation().setVisible(true);
				StudentViewSmall.getInstance().getConfirmation().setText(t.toString());
			}	
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		
		timer  = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				//schakel de hulpvraagknoppen weer in
				StudentViewSmall.getInstance().getBtnDAB().setEnabled(true);
				StudentViewSmall.getInstance().getBtnPRG().setEnabled(true);
				StudentViewSmall.getInstance().getBtnPRJ().setEnabled(true);
				StudentViewSmall.getInstance().getBtnBPV().setEnabled(true);
				StudentViewSmall.getInstance().getConfirmation().setVisible(false);
			}
		}, 5000);
	}
}